<?php
/*if($_GET['_a']==1)
{
	$id = $_GET['_d'];
	$page = $_GET['page'];
	$st = $_REQUEST['_st'];
	
	$q = mysql_fetch_array(mysql_query("select Status from picture where Id='$id'"));
	if($q["Status"]==1) $status = 0;
	else $status = 1;
	mysql_query("update picture set Status='$status', ApprovedDate=now() where Id='$id'") or die(mysql_error());
	header("location:index.php?tc=picture&_st=$st&page=$page&_s=1");
	exit;
}*/

if($_GET['_a']==2)
{
	$id = $_GET['_d'];
	$page = $_GET['page'];
	$st = $_REQUEST['_st'];
	
	$q = mysql_fetch_array(mysql_query("select Image from picture where Id='$id'"));
	$path = "../gallery/".$q["Image"];
	$path1 = "../gallery/thumb/".$q["Image"];
	@unlink($path);
	@unlink($path1);
	
	mysql_query("delete from picture where Id='$id'");
	
	//header("location:index.php?tc=picture&_st=$st&page=$page&_s=2");
	echo "<script>window.location='index.php?tc=picture&_st=$st&page=$page&_s=2'</script>";
	exit;
}
?>
<script language="javascript" type="text/javascript">
function show()
{
	document.ppf.action="index.php?tc=picture_add";
	document.ppf.submit();
}
</script>
<form name="ppf" method="post" action="#">
<table border="0" width="100%" align="center">
<tr>
	<td align="left"><span style="color:#1B78B7; font-size:14px; font-weight:bold">Picture</span>&nbsp;
	<input type="button" name="addnew" value="Add New" onclick="return show();" />
	</td>
	<td align="right">
    	<select name="_st" onChange="window.location='index.php?tc=picture&page=<?php echo $_REQUEST['page'];?>&_st='+this.value">
        	<option value="" <?php if($_REQUEST['_st']=="") echo "selected";?>><--Sort--></option>
            <option value="2" <?php if($_REQUEST['_st']==2) echo "selected";?>>All</option>
            <option value="1" <?php if($_REQUEST['_st']==1) echo "selected";?>>Approved Ads</option>
            <option value="3" <?php if($_REQUEST['_st']==3) echo "selected";?>>Pending Ads</option>
        </select>	    
    </td>
</tr>
<tr>
	<td background="images/topline.gif" colspan="2" height="11"></td>
</tr>    
</table>
</form>    
	<?php
if($_REQUEST['_s'] == 2)
{ ?>
	<table align="center" border="0">
	<tr>
    	<td align="center"><div class="sucmsg"><img src="images/information.png" align="absmiddle" />&nbsp;Deleted Successfully</div></td>
    </tr>    
    </table>
<?php } ?>
	<?php
if($_REQUEST['_s'] == 1)
{ ?>
	<table align="center" border="0">
	<tr>
    	<td align="center"><div class="sucmsg"><img src="images/information.png" align="absmiddle" />&nbsp;Updated Successfully</div></td>
    </tr>    
    </table>
<?php } ?>
<?php
if($_REQUEST['_s'] == 1)
{ ?>
	<table align="center" border="0">
	<tr>
    	<td align="center"><div class="sucmsg"><img src="images/information.png" align="absmiddle" />&nbsp;Updated Successfully</div></td>
    </tr>    
    </table>
<?php } ?>
<table width="100%" align="center" border="0" class="list">
<thead>
<tr>
	<td align="center" width="30">#</td>
	<td align="center" width="150">Title</td>
    <td align="center">Description</td>
    <td align="center" width="80">DateTaken</td>
    <td align="center" width="150">Name</td>
    <td align="center" width="160">Image</td>
    <td align="center" width="50">Status</td>
    <td align="center">Action</td>
</tr>
</thead>
<?php
include('includes/function.php');
$self="index.php?tc=picture&_st=".$_REQUEST['_st'];
$rowsPerPage = 20;
$pageNum = 1;
if(isset($_GET['page']))
{
	$pageNum = $_GET['page'];
}
if($_GET['page']=="")
{
	$pageNum = 1;
}

/*<!--counting the offset-->*/
$offset = ($pageNum - 1) * $rowsPerPage;
$st = $_REQUEST['_st'];

if($st == "" || $st == 2)
{
	$res = mysql_query("select Id from picture");
	$query = mysql_query("select Id, Title, Description, DateTaken, Name, Image, DATE_FORMAT(CreatedDate,'%d-%m-%Y') as insdate, Status from picture order by Id desc limit $offset , $rowsPerPage") or die(mysql_error());
}
else
{
	if($st == 3) $st=0;
	$res = mysql_query("select Id from picture where Status='$st'");
	
	$query = mysql_query("select Id, Title, Description, DateTaken, Name, Image, DATE_FORMAT(CreatedDate,'%d-%m-%Y') as insdate, Status from picture where Status='$st' order by Id desc limit $offset , $rowsPerPage");
}
$num = mysql_num_rows($query);
?>
<script type="text/javascript" src="includes/fancybox/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="includes/fancybox/jquery.mousewheel-3.0.2.pack.js"></script>
<script type="text/javascript" src="includes/fancybox/jquery.fancybox-1.3.1.js"></script>
<link rel="stylesheet" type="text/css" href="includes/fancybox/jquery.fancybox-1.3.1.css" media="screen" />
<link rel="stylesheet" href="includes/fancybox_style.css" />

<script type="text/javascript">
		$(document).ready(function() {
			/*
			*   Examples - images
			*/
			<?php
			for($j=1; $j<=$num;$j++)
			{ ?>
			$("a#<?php echo $j;?>").fancybox({
				'titleShow'		: false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic'
			});
			<?php } ?>
			$("a[rel=example_group]").fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'titlePosition' 	: 'over',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
			});

			/*
			*   Examples - various
			*/

			$("#various1").fancybox({
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
			});

			$("#various2").fancybox();

			$("#various3").fancybox({
				'width'				: '75%',
				'height'			: '75%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});

			$("#various4").fancybox({
				'padding'			: 0,
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
			});
		});
	</script>


<?php
$i = 1;
$imid = 1;
while($q = mysql_fetch_array($query))
{ 
	if($q["Status"] == 1) $status = "Approved";
	else $status = "Pending";
	?>
    <tr>
        <td align="center"><?php echo $i+$offset;?></td>
        <td align="left"><?php echo $q["Title"];?></td>
        <td align="left"><?php echo $q["Description"];?></td>
        <td align="center"><?php echo $q["DateTaken"];?></td>
        <td align="left"><?php echo $q["Name"];?></td>
        <td align="center"><a id="<?php echo $imid;?>" href="../gallery/<?php echo $q['Image'];?>"><img src="../gallery/thumb/<?php echo $q["Image"];?>" border="0" ></a></td>
        <td align="center"><?php echo $status;?></td>
        <td align="center">
        	<a href="index.php?tc=picture_view&_d=<?php echo $q['Id'];?>&page=<?php echo $pageNum;?>&_st=<?php echo $_REQUEST['_st'];?>">Edit</a><br><br>
            <a href="index.php?tc=picture&_d=<?php echo $q['Id'];?>&page=<?php echo $pageNum;?>&_a=2&_st=<?php echo $_REQUEST['_st'];?>" onClick="return confirm('Are you sure want to delete?');">Delete</a>
        </td>
   	</tr>     
<?php 
	$i++;
	$imid++;
}
?>
<?php 
if(mysql_num_rows($res) <= $rowsPerPage){	}
else { ?>
<tr>
    <td colspan="8" align="center"  bgcolor="#E3ECF3">
        <?php echo $paginglink=getPagingLink($res, $rowsPerPage,$pageNum,$self); ?>	
    </td>
</tr>
<?php } ?>
</table>    